#pragma strict
import System.Collections.Generic;
//////////////////////////////////////////////////////
///环形爆炸控制
//////////////////////////////////////////////////////
/**  */
var sparkPrefab:Transform;

/** 爆炸轨迹的 度数 */
var degrees:float[] = [0f,50,100,150,200,300];

var allPositions:List.<Vector3[]> = new List.<Vector3[]>();
/** 爆炸向外扩散的次数 */
var explodeCount:int = 3;
/** 每次爆炸的间隔时间 s */
var perExpDeltaTime:float = 0.5;
/** 同条爆炸线上,2次爆炸的距离 */
var perExpDeltaDistance:float = 2;
/** 每圈爆炸的间隔时间 */
var perExpCircleDeltaTime:float = 0.1;

function Start () {
	
}

function Update () {
	Check();
}

private function Check(){
	if(Input.GetMouseButtonDown(0)){
		var ray:Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		var hit:RaycastHit;
		if(Physics.Raycast(ray,hit)){
			SetupExpPos(hit.point);
			StartExplode();
		}
	}
}

private function SetupExpPos(pos:Vector3){
	allPositions.Clear();
	
	for(var degree:float in degrees){
		var q:Quaternion = Quaternion.Euler(0,degree,0);
		var dir:Vector3 = q * Vector3.forward;
		
		var positions:Vector3[] = new Vector3[explodeCount];
		for(var i:int = 0;i<positions.length;i++){
			positions[i] = pos + dir * ( (i + 1 )*perExpDeltaDistance);
		}
		allPositions.Add(positions);
	}
}

private function StartExplode(){
	for(var count:int = 0 ; count < explodeCount ; count ++){
		for(var i:int = 0 ; i < allPositions.Count ; i ++){
			var pos:Vector3 = allPositions[i][count];
			Instantiate(sparkPrefab,pos,Quaternion.identity);
			yield WaitForSeconds(perExpDeltaTime);
		}
		yield WaitForSeconds(perExpCircleDeltaTime);
	}
}